package com.hh.storeLogo.controller;
import com.hh.storeLogo.service.StoreLogoService;
import com.hh.storeLogo.vo.StoreLogoAddVo;
import com.hh.storeLogo.vo.StoreLogoUpdateStatusVo;
import com.hh.storeLogo.vo.StoreLogoUpdateVo;
import com.hh.storeLogo.vo.StoreLogoVo;
//import com.hh.storeLogo.vo.StoreLogoUpdateStatsusVo;
import com.hh.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping("/storeLogo")
public class StoreLogoController {

    @Autowired
    private StoreLogoService storeLogoService;

    /**
     * 库房标识查询接口
     * @param storeLogoVo
     * @return
     */
    @PostMapping("/queryPage")
    public ResultVo queryPage(@RequestBody StoreLogoVo storeLogoVo){
        return storeLogoService.queryPage(storeLogoVo);
    }

    /**
     *
     * 库房标识新增接口
     * @param storeLogoAddVo
     * @param bindingResult
     * @return
     */
    @PostMapping("add")
    public ResultVo add(@RequestBody @Valid StoreLogoAddVo storeLogoAddVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return ResultVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return storeLogoService.add(storeLogoAddVo);
    }

    /**
     * 库房标识修改接口
     * @param storeLogoUpdateVo
     * @param bindingResult
     * @return
     */
    @PostMapping("update")
    public ResultVo udapte(@RequestBody @Valid StoreLogoUpdateVo storeLogoUpdateVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return ResultVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return storeLogoService.update(storeLogoUpdateVo);
    }

    /**
     * 更新库房标识状态接口
     * @param storeLogeUpdateStatusVo
     * @return
     */
    @PostMapping("updateStatus")
    public ResultVo updateStatus(@RequestBody StoreLogoUpdateStatusVo storeLogeUpdateStatusVo){
        return storeLogoService.updateStatus(storeLogeUpdateStatusVo);
    }

    @GetMapping("logo")
    public ResultVo logo() {
        return storeLogoService.logo();
    }
}
